package com.example.shilehui;

import java.util.List;

import cn.jhc.Adapter.ListOfLoveAdapter;
import cn.jhc.bean.ListOfLove;
import cn.jhc.bean.PublicUserInfo;
import cn.jhc.service.ContactService;
import cn.jhc.service.DonateAtOnceService;
import cn.jhc.service.HelpTopicDataService;
import cn.jhc.service.PublicUserService;
import cn.jhc.utils.SharedMethod;
import cn.jhc.utils.URL;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.ListView;

public class ListOfLoveActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		init();
	}

	private void init() {
		setContentView(R.layout.list_of_love);
		//setDown
		Intent intent=getIntent();
		final String url=intent.getStringExtra("url");
		if(SharedMethod.getInstance().isNetWorkConnected(this)){
			Runnable downloadRun = new Runnable() {
				
				@Override
				public void run() {
					ListView list_of_love_listview =(ListView) findViewById(R.id.list_of_love_listview); 
					List<ListOfLove> listOfLoves=HelpTopicDataService.getInstance().getListOfLove(
							ContactService.getInstance().getJSONData(url));
					handler.sendMessage(handler.obtainMessage(10,
							listOfLoves));
				}
			};
			new Thread(downloadRun).start();
		}else{
			SharedMethod.getInstance().showTextToast(SharedMethod.getInstance().getNoNetWorkConnected(), this);
		}
		
		
	}

	Handler handler = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			
			ListView list_of_love_listview =(ListView) findViewById(R.id.list_of_love_listview); 
			List<ListOfLove> listOfLoves=(List<ListOfLove>) msg.obj;
			if(listOfLoves!=null){
				ListOfLoveAdapter adapter=new ListOfLoveAdapter(ListOfLoveActivity.this,R.layout.list_of_love_listview_item,listOfLoves);
				list_of_love_listview.setAdapter(adapter);
			}else{
				SharedMethod.getInstance().showTextToast(SharedMethod.getInstance().getNoData(), ListOfLoveActivity.this);
			}
		}
		
	};

	public void list_of_love_title_back(View v){
		finish();
	}
	
}
